package com.xp.tinyurl.common.utils;


import com.xp.tinyurl.common.enums.ExpiredEnum;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

/**
 * @author  (xp)
 **/
public class ExpiredEnumUtil {
    public static Date toDate(ExpiredEnum expiredEnum) {
        switch (expiredEnum) {
            case THREE_MONTHS:
                return Date.from(LocalDateTime.now().plusMonths(3).toInstant(ZoneOffset.of("+8")));
            case ONE_YEAR:
                return Date.from(LocalDateTime.now().plusYears(1).toInstant(ZoneOffset.of("+8")));
            case FOREVER:
                return Date.from(LocalDateTime.now().plusYears(99).toInstant(ZoneOffset.of("+8")));
            default:
                return Date.from(LocalDateTime.now().plusDays(1).toInstant(ZoneOffset.of("+8")));
        }
    }

    public static long toTimestamp(ExpiredEnum expiredEnum) {
        return toDate(expiredEnum).getTime();
    }
}
